#include <iostream>
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <queue>
using namespace std;

int l, r, c;
bool vis[35][35][35];
bool mp[35][35][35];
int sx, sy, sz, tx, ty, tz;
int d[][3] = {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}};

struct node {
	int x, y, z, step;
	node(int i, int j, int k, int s) {
		x = i; z = k;
		y = j; step = s;
	}
};

int bfs() {
	queue<node> q;
	q.push(node(sx, sy, sz, 0));
	while (q.size()) {
		node x = q.front();
		q.pop();

		if (x.x == tx && x.y == ty && x.z == tz) {
			return x.step;
		}

		if (!mp[x.x][x.y][x.z]) continue;
		if (vis[x.x][x.y][x.z]) continue;
		vis[x.x][x.y][x.z] = 1;

		for (int i = 0; i < 6; ++i) {
			q.push(node(x.x + d[i][0], x.y + d[i][1], x.z + d[i][2], x.step + 1));
		}
	}
	return -1;
}

int main() {
	string e;
	while (1) {
		cin >> l >> r >> c;
		if (l == 0 && r == 0 && c == 0) break;
		if (l == 0 || r == 0 || c == 0) continue;
		for (int i = 1; i <= l; ++i) {
			for (int j = 1; j <= r; ++j) {
				cin >> e;
				for (int k = 0; k < c; ++k) {
					if (e[k] == '.') {
						mp[i][j][k+1] = 1;
					} else if (e[k] == 'E') {
						mp[i][j][k+1] = 1;
						tx = i; ty = j; tz = k + 1;
					} else if (e[k] == 'S') {
						mp[i][j][k+1] = 1;
						sx = i; sy = j; sz = k + 1;
					} else {
						mp[i][j][k+1] = 0;
					}
 				}
			}
		}
/*
		printf("\n");
		
		printf("\n%d %d %d\n", sx, sy, sz);
		printf("%d %d %d\n", tx, ty, tz);

		for (int i = 1; i <= l; ++i) {
			for (int j = 1; j <= r; ++j) {
				for (int k = 1; k <= c; ++k) {
					printf("%d ", mp[i][j][k]);
 				}
 				printf("\n");
			}
			printf("\n");
		}
	*/

		int ans = bfs();
		if (ans == -1) {
			printf("Trapped!\n");
		} else {
			printf("Escaped in %d minute(s).\n", ans);
		}

		memset(mp, 0, sizeof(mp));
		memset(vis, 0, sizeof(vis));
	}
	return 0;
}